﻿using System;
using System.Collections;
using System.Data;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aspose.Cells;
using BLL;
using Ysb.Components;
using System.Text.RegularExpressions;
public partial class Admin_ToExcel : System.Web.UI.Page
{
    string id;
    Tools tool = new Tools();
    PublicSqlService ps = new PublicSqlService();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!AdminCheck.Check(this, 1))
        {
            Response.Redirect(AdminCheck.RedirectPage);
        }

        if (!Page.IsPostBack)
        {
            id = "1";//设置为公司ID
        }
    }
    protected void okbtn_Click(object sender, ImageClickEventArgs e)
    {

        string name = "";

        UploadFile up = new UploadFile(".xls", 10000, "temp");
        if (up.UpLoad(fileselecet))
        {
            name = up.FileName;
        }
        else
        {
            Tools.OpenWindow(this, up.ErrorMessage);
            return;
        }



        ToExcel(name);


    }

    void ToExcel(string nme)
    {




        try
        {
            Workbook wb = new Workbook();

            wb.LoadData(ApplicationInfo.PhysicalApplicationPath + "\\Temp\\" + nme);
            Worksheet ws = wb.Worksheets[0];
            //   Worksheet ws1 = wb.Worksheets[1];

            if (billselee.SelectedItem.Value.Trim() == "1")
            {

                DataTable dt = ws.Cells.ExportDataTable(0, 0, ws.Cells.MaxDataRow + 1, ws.Cells.MaxColumn + 1, true);
                InsertBill(dt);
            }

            if (billselee.SelectedItem.Value.Trim() == "2")
            {
                DataTable dt1 = ws.Cells.ExportDataTable(0, 0, ws.Cells.MaxDataRow + 1, ws.Cells.MaxColumn + 1, true);


                InsertState(dt1);
            }
            if (billselee.SelectedItem.Value.Trim() == "3")
            {
                DataTable dt2 = ws.Cells.ExportDataTable(0, 0, ws.Cells.MaxDataRow + 1, ws.Cells.MaxColumn + 1, true);


                USA(dt2);
            }

            if (billselee.SelectedItem.Value.Trim() == "4")
            {
                DataTable dt3 = ws.Cells.ExportDataTable(0, 0, ws.Cells.MaxDataRow + 1, ws.Cells.MaxColumn + 1, true);


                CN(dt3);
            }
            if (billselee.SelectedItem.Value.Trim() == "5")
            {
                DataTable dt4 = ws.Cells.ExportDataTable(0, 0, ws.Cells.MaxDataRow + 1, ws.Cells.MaxColumn + 1, true);


                Daihao(dt4);
            }



        }
        catch (Exception ex)
        {
            //Response.Write(ex.Message);
            Tools.OpenWindow(this, ex.Message);
        }


    }
    void InsertBill(DataTable dt)
    {
        if (dt.Columns.Count != 34)
        {
            Tools.OpenWindow(this, "单据模板错误！请重新下载");
            return;
        }

        //show.DataSource = dt;
        //show.DataBind();
        //return;
        PublicSqlService ps = new PublicSqlService();
        Hashtable hs = new Hashtable();
        int ok = 0;
        string err = "";
        int cont = 0;
        int bcount = 0;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            cont++;
            hs.Clear();
            string n = dt.Rows[i][0].ToString().Trim();
            if (n == "")
            {
                bcount++;
                continue;
            }
            Regex rg = new Regex("^[0-9]{9,10}$");

            if (!rg.IsMatch(n))
            {
                bcount++;
                continue;
            }

            if (n.Trim().Length == 10)
            {
                n = n.Trim().Substring(1);
            }

            if (ps.GetCoun("BID", "Tbl_WayBill", "TrackingNo='" + n + "'") != 0)
            {
                if (relaceselect.SelectedItem.Value.Trim() == "2")
                {
                    //如果是选择保留 跳过
                    bcount++;
                    continue;

                }
                else
                {
                    //替换，删除以前数据
                    ps.Del("Tbl_WayBill", "TrackingNo='" + n + "'");
                }
            }
            string userid = "1";//支付账号 如果为空，默认为 散客
            string acc = "upex00001";
            if (dt.Rows[i][1].ToString().Trim() == "")
            {
                string user = new PublicSqlService().GetWords("TblUserInfo", "UID", "AccountNo='" + dt.Rows[i][1].ToString().Trim() + "'");
                if (user.Trim() != "")
                {
                    userid = user;
                    acc = dt.Rows[i][1].ToString();
                }

            }





            hs.Add("CreateUserID", userid);
            hs.Add("CreateDate", DateTime.Now);
            hs.Add("AccountNo", acc);
            hs.Add("TrackingNo", n);
            #region   发送人基本属性
            hs.Add("Sender", dt.Rows[i][2]);//名字C
            hs.Add("FromFaxNo", "");
            hs.Add("FromPhoneNo", dt.Rows[i][3]);//电话 D
            hs.Add("FromCompany", dt.Rows[i][4]);//公司/E
            hs.Add("FromAddress", dt.Rows[i][5]);//地址F
            hs.Add("FromCity", "");
            hs.Add("FromState", "");

            hs.Add("FromZIPCode", "");
            #endregion
            #region   收件人基本属性

            hs.Add("Receiver", dt.Rows[i][6]);//收件人 G
            hs.Add("ToPhoneNo", dt.Rows[i][7]);//收件电话H
            hs.Add("ToCompany", dt.Rows[i][8]);//i
            hs.Add("ToAddress", dt.Rows[i][9]);//j
            hs.Add("ToCity", "");
            hs.Add("ToState", "");
            hs.Add("ToCountry", "");
            hs.Add("ToZIPCode", "");
            #endregion
            #region 其他相关属性
            hs.Add("FlightNo", dt.Rows[i][10]);//参考K
            hs.Add("AerialNo", dt.Rows[i][13]);//航空单号N
            // hs.Add("CreateUserID", id);
            hs.Add("Origin", dt.Rows[i][11]);//L
            hs.Add("Destination", dt.Rows[i][12]);//M
            //支付方式
            string pay = "2";
            string zf = dt.Rows[i][19].ToString().Trim();
            int sz = new Tools().StringToIntDif(zf, -10);
            if (sz == -10)
            {
                //不是数字

                string pid = ps.GetWords("Tbl_PayModel", "PID", "ModelName='" + zf + "'");
                if (pid.Trim() != "")
                {
                    pay = pid;
                }
            }
            else
            {
                if (sz > 0 && sz < 5)
                {
                    pay = sz.ToString();
                }

            }


            hs.Add("Payment", pay);//T




            hs.Add("Sep", 0);
            //包装形式

            string pk = "0";
            switch (dt.Rows[i][15].ToString().Trim())
            {
                case "0":
                    pk = "0";
                    break;
                case "1":
                    pk = "1";
                    break;
                case "2":
                    pk = "2";
                    break;
                case "文件":
                    pk = "0";
                    break;
                case "私人包裹":
                    pk = "1";
                    break;
                case "商业样品":
                    break;
                    pk = "2";
                    break;

            }
            hs.Add("Packing", pk);//P






            hs.Add("DestPaidBy", 0);

            //保价费

            hs.Add("ShipmentInsurance", 0);
            hs.Add("InsurancePrice", 0);
            hs.Add("InsuredValue", 0);
            #endregion
            #region 质量 体积
            hs.Add("NoOfPiece", 1); //默认1 有分单  按照分单数计算
            hs.Add("TotalWeight", tool.StringToDecimalDif(dt.Rows[i][14]));//重重量O
            hs.Add("DimensionsH", tool.StringToDecimalDif(dt.Rows[i][16]));//q
            hs.Add("DimensionsL", tool.StringToDecimalDif(dt.Rows[i][17]));//r
            hs.Add("DimensionsW", tool.StringToDecimalDif(dt.Rows[i][18]));//s

            hs.Add("DimensionsStyle", 0);

            hs.Add("DimensionsWeight", 0);//体积重量

            #endregion
            #region  价格
            hs.Add("ChargedWt", tool.StringToDecimalDif(dt.Rows[i][21]));//收费重量V
            // hs.Add("DeclarePrice", (tool.StringToDecimalDif(StrHelper.VldNull(allprice.Text.Trim())) > PirceSum * PriceRate) ? PirceSum * PriceRate : tool.StringToDecimalDif(StrHelper.VldNull(allprice.Text.Trim())));
            hs.Add("FreightCharge", tool.StringToDecimalDif(dt.Rows[i][23]));//重量收费x
            hs.Add("DeclarePrice", tool.StringToDecimalDif(dt.Rows[i][33]));//海关申报价AH
            hs.Add("Memo2", tool.StringToDecimalDif(dt.Rows[i][24]));//垫付费Y
            hs.Add("Memo3", tool.StringToDecimalDif(dt.Rows[i][25]));//代购费Z
            hs.Add("Memo4", tool.StringToDecimalDif(dt.Rows[i][26]));//包装费AA
            hs.Add("Duties", tool.StringToDecimalDif(dt.Rows[i][27]));//关税AB
            hs.Add("Premium", tool.StringToDecimalDif(dt.Rows[i][28]));//保险费ac
            hs.Add("OtherCharge", tool.StringToDecimalDif(dt.Rows[i][29]));//其他费用AD
            hs.Add("Memo5", tool.StringToDecimalDif(dt.Rows[i][30]));//优惠//AE
            hs.Add("Total", tool.StringToDecimalDif(dt.Rows[i][20]));//总费用U
            #endregion
            #region  状态
            hs.Add("BankID", 1);
            hs.Add("UPEXState", "可编辑");
            hs.Add("BillState", 1);
            hs.Add("IsPlot", 0);
            hs.Add("StateId", 1);
            hs.Add("Complete", 0);
            hs.Add("BillingCopyDate", DateTime.Now);
            if (new PublicSqlService().Insert(hs, "Tbl_WayBill"))
            {
                new WayBillService().UPBillPriceByTno(n);
                ps.Del("TblShipment", "TrackingNo='" + n + "'");
                hs.Clear();
                hs.Add("TrackingNo", n);
                hs.Add("Commodity", dt.Rows[0][31]);//Af
                hs.Add("Qty", tool.StringToIntDif(dt.Rows[0][32]));//Ag
                hs.Add("UnitValue", 0);
                hs.Add("ValueForCustoms", tool.StringToDecimalDif(dt.Rows[0][33]));//AH
                ps.Insert(hs, "TblShipment");


                ok++;
            }
            else
            {
                err += "," + n;
            }

            #endregion

        }
        Tools.OpenWindow(this, "单据导入完成：<br/>成功保存单据数据量：" + ok + "<br/> 数据行：" + cont + " 其中 跳过数据：" + bcount.ToString() + "<br/>保存失败单据：<br/>" + err + "<br/>无法导入的数据请检查单号");


    }
    //状态导入
    void InsertState(DataTable dt)
    {
        if (dt.Columns.Count != 6)
        {
            Tools.OpenWindow(this, "单据状态模板错误！请重新下载");
            return;
        }
        Hashtable hs = new Hashtable();
        PublicSqlService ps = new PublicSqlService();
        int iok = 0;
        int editok = 0;
        string err = "";
        string otherErr = "";
        WayBillService ws = new WayBillService();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            bool Sep = false;
            if (dt.Rows[i][0].ToString().Trim() == "")
            {
                continue;
            }
            string n = dt.Rows[i][0].ToString().Trim();
            Regex rg = new Regex("^[0-9]{8,10}$");


            if (!rg.IsMatch(n))
            {
    //            otherErr += "单据号：" + n + " 不符合规则，未导入<br/>";
     //           continue;
            }

            if (n.Trim().Substring(0, 1) != "4" && n.Trim().Substring(0, 1) != "6"  )
            {
                //主单验证是否存在
                if (ps.GetCoun("BID", "Tbl_WayBill", "TrackingNo='" + n + "'") == 0)
                {
                    otherErr += "主单单据号：" + n + " 当前主单不存在，未导入<br/>";
                    continue;
                }
                else
                {
                    Sep = false;
                }
            }
            else
            {
                if (n.Trim().Substring(0, 1) == "4" || n.Trim().Substring(0, 1) == "6")
                {
                    if (ps.GetCoun("SID", "Tbl_SepBill", "SepNo='" + n + "'") == 0)
                    {
                        otherErr += "分单单据号：" + n + " 当前分单不存在，未导入<br/>";
                        continue;
                    }
                    else
                    {
                        Sep = true;
                    }
                }
                else
                {
                    //不合法输入 跳过
            //        otherErr += "单据号：" + n + " 不符合规则，未导入<br/>";
             //       continue;
                }
            }


            hs.Clear();
            hs.Add("SepNo", n);
            hs.Add("Date", tool.StringToTime(dt.Rows[i][1].ToString()));
            hs.Add("RecordDate", DateTime.Now);
            hs.Add("RecorderID", Session["uid"].ToString());
            hs.Add("Remark", dt.Rows[i][5].ToString());
            //状态
            #region 获取状态 ID
            string state = "1";
            string statelb = dt.Rows[i][2].ToString().Trim();

            int stateid = new Tools().StringToIntDif(statelb, -10);

            if (stateid != -10)
            {
                if (stateid < 23)
                {
                    state = stateid.ToString();
                }
            }
            else
            {
                //字符
                string statwod = ps.GetWords("Tbl_BillState", "BSID", "Description='" + statelb + "'");
                if (statwod.Trim() != "")
                {
                    state = statwod.Trim();
                }
            }
            #endregion
            hs.Add("StateID", state);
            #region 获取公司ID
            string gsstate = "0";
            string gsstatelb = dt.Rows[i][3].ToString().Trim();

            int gsstateid = new Tools().StringToIntDif(gsstatelb, -10);

            if (gsstateid != -10)
            {

                gsstate = gsstateid.ToString();

            }
            else
            {
                //字符
                string gsstatwod = ps.GetWords("TblDomesticShipping", "id", "CompanyName='" + gsstatelb + "'");
                if (gsstatwod.Trim() != "")
                {
                    gsstate = gsstatwod.Trim();
                }


            }
            #endregion
            hs.Add("CompanyNo", dt.Rows[i][4].ToString());
            hs.Add("CompanyID", gsstate);


            #region

            //当前状态无 新录入状态
            if (ps.Insert(hs, "Tbl_BillStateRec"))
            {
                iok++;
                if (Sep)
                {
                    ws.UpdateSepState(n, state);//更新分单

                }
                else
                {
                    ws.UpdateState(n, state);//更新主单状态
                }
            }
            else
            {
                otherErr += "单据号：" + n + " 导入失败，未导入<br/>";
            }




        }
            #endregion


        Tools.OpenWindow(this, "单据状态导入完成：<br/>写入状态数据量：" + iok + "<br/>编辑状态数量：" + editok + "<br/> 保存失败单据状态历史：<br/>" + otherErr);


    }
    void InsertStateErr(DataTable dt)
    {
        if (dt.Columns.Count != 6)
        {
            Tools.OpenWindow(this, "单据状态模板错误！请重新下载");
            return;
        }
        Hashtable hs = new Hashtable();
        PublicSqlService ps = new PublicSqlService();
        int iok = 0;
        int editok = 0;
        string err = "";
        string otherErr = "";
        WayBillService ws = new WayBillService();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            bool Sep = false;
            if (dt.Rows[i][0].ToString().Trim() == "")
            {
                continue;
            }
            string n = dt.Rows[i][0].ToString().Trim();
            Regex rg = new Regex("^[0-9]{8,10}$");


            if (!rg.IsMatch(n))
            {
          //      otherErr += "单据号：" + n + " 不符合规则，未导入<br/>";
         //       continue;
            }
            int billtype = -1;//返回的类型  1代表 普通单据号 0代表 分单  -1 代表错误

            if (!BillPublic.IsOkNo(n, ref billtype))
            {
                return;//不是不是正确的单据
            }

            if (billtype == 1)
            {
                //主单验证是否存在
                if (ps.GetCoun("BID", "Tbl_WayBill", "TrackingNo='" + n + "'") == 0)
                {
                    otherErr += "主单单据号：" + n + " 当前主单不存在，未导入<br/>";
                    continue;
                }
                else
                {
                    Sep = false;
                }
            }
            else
            {
                if (n.Length > 7 && n.Length < 11)
                {
                    if (ps.GetCoun("SID", "Tbl_SepBill", "SepNo='" + n + "'") == 0)
                    {
                        otherErr += "分单单据号：" + n + " 当前分单不存在，未导入<br/>";
                        continue;
                    }
                    else
                    {
                        Sep = true;
                    }
                }
                else
                {
                    //不合法输入 跳过
                    otherErr += "单据号：" + n + " 不符合规则，未导入<br/>";
                    continue;
                }
            }


            hs.Clear();
            hs.Add("SepNo", n);
            hs.Add("Date", tool.StringToTime(dt.Rows[i][1].ToString()));
            hs.Add("RecordDate", DateTime.Now);
            hs.Add("RecorderID", Session["uid"].ToString());
            hs.Add("Remark", dt.Rows[i][5].ToString());
            //状态
            #region 获取状态 ID
            string state = "1";
            string statelb = dt.Rows[i][2].ToString().Trim();

            int stateid = new Tools().StringToIntDif(statelb, -10);

            if (stateid != -10)
            {
                if (stateid < 23)
                {
                    state = stateid.ToString();
                }
            }
            else
            {
                //字符
                string statwod = ps.GetWords("Tbl_BillState", "BSID", "Description='" + statelb + "'");
                if (statwod.Trim() != "")
                {
                    state = statwod.Trim();
                }
            }
            #endregion
            hs.Add("StateID", state);
            #region 获取公司ID
            string gsstate = "0";
            string gsstatelb = dt.Rows[i][3].ToString().Trim();

            int gsstateid = new Tools().StringToIntDif(gsstatelb, -10);

            if (gsstateid != -10)
            {
                if (gsstateid < 23)
                {
                    gsstate = gsstateid.ToString();
                }
            }
            else
            {
                //字符
                string gsstatwod = ps.GetWords("TblDomesticShipping", "id", "CompanyName='" + gsstatelb + "'");
                if (gsstatwod.Trim() != "")
                {
                    gsstate = gsstatwod.Trim();
                }


            }
            #endregion
            hs.Add("CompanyNo", dt.Rows[i][4].ToString());
            hs.Add("CompanyID", gsstate);


            #region

            if (ps.GetCoun("BSRID", "Tbl_BillStateRec", "SepNo='" + dt.Rows[i][0].ToString().Trim() + "' and StateID=" + state) != 0)
            {
                //有
                if (relaceselect.SelectedItem.Value.Trim() == "1")
                {
                    //替换

                    if (ps.Update(hs, "Tbl_BillStateRec", "SepNo='" + dt.Rows[i][0].ToString().Trim() + "' and StateID=" + state))
                    {
                        editok++;
                        if (Sep)
                        {
                            ws.UpdateSepState(n, state);//更新分单

                        }
                        else
                        {
                            ws.UpdateState(n, state);//更新主单状态
                        }
                    }
                    else
                    {
                        //err += "," + dt.Rows[i][0].ToString();
                        otherErr += "单据号：" + n + " 导入失败，未导入<br/>";
                    }

                }
                else
                {
                    otherErr += "单据号：" + n + " 状态存在，使用策略 【跳过】，未导入<br/>";


                    continue;
                }
            }

            else
            {
                //当前状态无 新录入状态
                if (ps.Insert(hs, "Tbl_BillStateRec"))
                {
                    iok++;
                    if (Sep)
                    {
                        ws.UpdateSepState(n, state);//更新分单

                    }
                    else
                    {
                        ws.UpdateState(n, state);//更新主单状态
                    }
                }
                else
                {
                    otherErr += "单据号：" + n + " 导入失败，未导入<br/>";
                }

            }


        }

            #endregion


        Tools.OpenWindow(this, "单据状态导入完成：<br/>写入状态数据量：" + iok + "<br/>编辑状态数量：" + editok + "<br/> 保存失败单据状态历史：<br/>" + otherErr);


    }
    void USA(DataTable dt)
    {
        if (dt.Columns.Count != 5)
        {
            Tools.OpenWindow(this, "美国地址模板错误！请重新下载");
            return;
        }
        Hashtable hs = new Hashtable();
        PublicSqlService ps = new PublicSqlService();
        int ok = 0;

        WayBillService ws = new WayBillService();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i][0].ToString().Trim() == "")
            {
                continue;
            }
            hs.Add("Address", dt.Rows[i][1].ToString().Trim());
            hs.Add("Name", dt.Rows[i][0].ToString().Trim());
            hs.Add("City", dt.Rows[i][3].ToString().Trim());
            hs.Add("State", dt.Rows[i][4].ToString().Trim());
            hs.Add("Tel", dt.Rows[i][2].ToString().Trim());
            string id = ps.GetWords("Tbl_BillAddress", "AID", "Name='" + dt.Rows[i][0].ToString().Trim() + "'");
            if (id.Trim() == "")
            {
                //不存在
                if (ps.Insert(hs, "Tbl_BillAddress"))
                {
                    ok++;
                }
                else
                {

                }
            }
            else
            {

                if (relaceselect.SelectedValue.Trim() == "1")
                {
                    if (ps.Update(hs, "Tbl_BillAddress", "AID=" + id))
                    {
                        ok++;
                    }
                }
            }


        }
        Tools.OpenWindow(this, "美国地址导入完成： <br/>成功数量：" + ok + "条");

    }
    void CN(DataTable dt)
    {
        if (dt.Columns.Count != 10)
        {
            Tools.OpenWindow(this, "分单地址模板错误！请重新下载");
            return;
        }
        Hashtable hs = new Hashtable();
        PublicSqlService ps = new PublicSqlService();
        int ok = 0;

        WayBillService ws = new WayBillService();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i][0].ToString().Trim() == "")
            {
                continue;
            }
            hs.Add("UserName", dt.Rows[i][0].ToString().Trim());
            hs.Add("Address", dt.Rows[i][1].ToString().Trim());
            hs.Add("TelNo", dt.Rows[i][2].ToString().Trim());
            hs.Add("City", dt.Rows[i][5].ToString().Trim());
            hs.Add("Country", dt.Rows[i][7].ToString().Trim());
            hs.Add("IDCardNo", dt.Rows[i][4].ToString().Trim());
            hs.Add("State", dt.Rows[i][6].ToString().Trim());
            hs.Add("ZIPCode", dt.Rows[i][8].ToString().Trim());
            hs.Add("IDCardPic", "");
            hs.Add("Company", dt.Rows[i][3].ToString().Trim());
            string value = dt.Rows[i][9].ToString().Trim();
            int nid = 1;
            nid = tool.StringToIntDif(value);
            if (nid == 0)
            {
                nid = tool.StringToIntDif(ps.GetWords("Tbl_AddressType", "ID", "Name='" + value.Trim() + "'"), 1);
            }
            hs.Add("AddressType", nid);

            string id = ps.GetWords("Tbl_SplitBillUser", "ID", "UserName='" + dt.Rows[i][0].ToString().Trim() + "'");
            if (id.Trim() == "")
            {

                hs.Add("PostTime", DateTime.Now);
                hs.Add("LastActiveDate", DateTime.Now.AddDays(-1));
                //不存在
                if (ps.Insert(hs, "Tbl_SplitBillUser"))
                {
                    ok++;
                }
                else
                {

                }
            }
            else
            {

                if (relaceselect.SelectedValue.Trim() == "1")
                {
                    if (ps.Update(hs, "Tbl_SplitBillUser", "ID=" + id))
                    {
                        ok++;
                    }
                }
            }


        }
        Tools.OpenWindow(this, "分单地址导入完成： <br/>成功数量：" + ok + "条");
    }
    void Daihao(DataTable dt)
    {
        if (dt.Columns.Count != 3)
        {
            Tools.OpenWindow(this, "分单袋号修改模板错误！请重新下载");
            return;
        }


        Hashtable hs = new Hashtable();
        PublicSqlService ps = new PublicSqlService();
        int ok = 0;

        string err = "";
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string sepno = dt.Rows[i][0].ToString().Trim();
            if (sepno == "")
            {
                continue;
            }

            Regex rg = new Regex("^[0-9]{8,10}$");


            if (!rg.IsMatch(sepno))
            {
                err += "分单单据号：" + sepno + " 不是分单，未修改袋号！<br/>";
                continue;
            }
            //if (sepno.Length != 8)
            //{
            //    err += "分单单据号：" + sepno + " 不是分单，未修改袋号！<br/>";
            //    continue;

            //}
            if (ps.GetCoun("Sid", "Tbl_SepBill", "SepNo='" + sepno + "'") == 0)
            {
                err += "分单单据号：" + sepno + " 不存在，未修改袋号！<br/>";
                continue;
            }


            hs.Add("Description", dt.Rows[i][1].ToString().Trim());
            if (dt.Rows[i][2].ToString().Trim() != "")
            {
                hs.Add("AerialNo", dt.Rows[i][2].ToString().Trim());
            }
            if (ps.Update(hs, "Tbl_SepBill", "SepNo='" + sepno + "'"))
            {
                ok++;
            }
            else
            {
                err += "分单单据号：" + sepno + " 袋号保存失败！<br/>";
            }


        }
        Tools.OpenWindow(this, "分单袋号批量修改完成： <br/>成功数量：" + ok + "条,其他信息：<br/>" + err);
    }

}
